﻿using System;
using System.Collections.Generic;

using mvcForum.Core;
using mvcForum.Core.Interfaces;
using mvcForum.Core.Specifications;
using mvcForum.Core.Interfaces.Data;

namespace mvcForum.AddOns.NewUserTrial {

	public class NewUserTrialInstall : IInstallable {
		private readonly IRepository<AddOnConfiguration> configRepo;
		private readonly IRepository<Group> groupRepo;

		public NewUserTrialInstall(IRepository<AddOnConfiguration> configRepo, IRepository<Group> groupRepo) {
			this.configRepo = configRepo;
			this.groupRepo = groupRepo;
		}

		public void Install() {
			NewUserTrialConfiguration config = new NewUserTrialConfiguration(this.configRepo);
			config.Enabled = true;
			config.AutoLimit = 2;
			config.RunAsynchronously = false;
			config.Delay = 5;

			List<Int32> groups = new List<Int32>();
			Group adminGroup = this.groupRepo.ReadOne(new GroupSpecifications.SpecificName("Administrator"));
			if (adminGroup != null) {
				groups.Add(adminGroup.Id);
			}

			Group moderatorGroup = this.groupRepo.ReadOne(new GroupSpecifications.SpecificName("Moderator"));
			if (moderatorGroup != null) {
				groups.Add(moderatorGroup.Id);
			}

			config.ExcludeGroups = groups;
		}
	}
}